package com.css.zfzx.fwsjcj.modules.analysis.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.base.response.RestResponse;
import com.css.zfzx.fwsjcj.modules.analysis.service.SiftAnalysisService;
import com.css.zfzx.fwsjcj.modules.analysis.vo.AnalysisQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author leon
 * @Title: SiftAnalysisController
 * @Description: 详查统计分析
 * @date 2020/6/11 19:02
 */
@Slf4j
@RestController
@RequestMapping("fw/siftAnalysis")
public class SiftAnalysisController {
    @Autowired
    private SiftAnalysisService siftAnalysisService;


    /**
     * 柱状图-个数
     *
     * @param analysisQueryVo
     * @return
     */
    @GetMapping("buildingNum")
    public RestResponse buildingNum(AnalysisQueryVo analysisQueryVo) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try {
            Map<String, Object> data = siftAnalysisService.buildingNumData(analysisQueryVo);
            json.put("data", data);
            json.put("message", "查询成功!");
            response = RestResponse.succeed(json);
        } catch (Exception e) {
            String errorMessage = "查询失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /**
     * 柱状图-面积
     *
     * @param analysisQueryVo
     * @return
     */
    @GetMapping("buildingArea")
    public RestResponse buildingArea(AnalysisQueryVo analysisQueryVo) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try {
            Map<String, Object> data = siftAnalysisService.buildingAreaData(analysisQueryVo);
            json.put("data", data);
            json.put("message", "查询成功!");
            response = RestResponse.succeed(json);
        } catch (Exception e) {
            String errorMessage = "查询失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /**
     * 饼状图-建造年代-个数和面积
     *
     * @param analysisQueryVo
     * @return
     */
    @GetMapping("buildingTime")
    public RestResponse buildingDataByBuildingTime(AnalysisQueryVo analysisQueryVo) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try {
            // 建筑栋数和面积
            List<Map> num = siftAnalysisService.buildingNumDataByBuildingTime(analysisQueryVo);
            List<Map> area = siftAnalysisService.buildingAreaDataByBuildingTime(analysisQueryVo);
            json.put("num", num);
            json.put("area", area);
            json.put("message", "查询成功!");
            response = RestResponse.succeed(json);
        } catch (Exception e) {
            String errorMessage = "查询失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }


    /**
     * 饼状图-设防烈度-个数和面积
     *
     * @param analysisQueryVo
     * @return
     */
    @GetMapping("fortificationIntensity")
    public RestResponse buildingDataByFortificationIntensity(AnalysisQueryVo analysisQueryVo) {
        RestResponse response = null;
        JSONObject json = new JSONObject();
        try {
            // 栋数和面积
            List<Map> num = siftAnalysisService.buildingNumDataByFortificationIntensity(analysisQueryVo);
            List<Map> area = siftAnalysisService.buildingAreaDataByFortificationIntensity(analysisQueryVo);
            json.put("num", num);
            json.put("area", area);
            json.put("message", "查询成功!");
            response = RestResponse.succeed(json);
        } catch (Exception e) {
            String errorMessage = "查询失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
}
